package com.wuyou.designPatterns.iterator;

/**
 * @Description 实际迭代器
 * @Author yh.zhang
 * @Date 2024/1/10 16:42
 */
public class BookShelfIterator implements Iterator{

    private BookShelf bookShelf;

    private int index;

    public BookShelfIterator(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
        this.index = 0;
    }

    @Override
    public Object next() {
        return bookShelf.getBookAt(this.index++);
    }

    @Override
    public boolean hasNext() {
        if (index < bookShelf.getLength()) {
            return true;
        }
        return false;
    }
}
